/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

/*
 * This Class is not use in this project.
 */

package wads.app;

import wads.drawing.line.CaseLink;
import wads.drawing.node.CaseNode;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Enumeration;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class CaseEditorDocDialog extends JDialog {
//  private static final long serialVersionUID = 5309486776353586266L;
  
  private JTextArea textArea;

  public CaseEditorDocDialog() {
    super();
    setTitle("Generated Documentation");

    //Init panel and text panes
    textArea = new JTextArea();

    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    JScrollPane scrollPane = new JScrollPane();
    textArea = new JTextArea();
    scrollPane.getViewport().add(textArea,"Center");
    textArea.setSize(400,300);

    panel.add(scrollPane);

    //Add buttons
    JPanel buttonsPanel = new JPanel();
    JButton okButton = new JButton("Ok");
    JButton cancelButton = new JButton("Cancel");
    okButton.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent evt){
        CaseEditorDocDialog.this.setVisible(false);
      }
    });

    cancelButton.addActionListener(new ActionListener(){
      @Override
      public void actionPerformed(ActionEvent evt){
        CaseEditorDocDialog.this.setVisible(false);
      }
    });

    buttonsPanel.add(okButton);
    buttonsPanel.add(cancelButton);
    this.getContentPane().add(panel,"Center");
    this.getContentPane().add(buttonsPanel,"South");

    this.setSize(400,300);
    setResizable(true);
    this.setModal(false); // allow editing to continue while viewing
  }

  public void appendNodeDoc(CaseNode node) {
    textArea.append("\n");
    String content[] = node.getContent();
    String title[] = node.getContentTitle();
    StringBuffer nodeTitle = new StringBuffer();
    nodeTitle.append("--[ " + node.getName());
    nodeTitle.append(" : ");
    nodeTitle.append(content[0] + " ]--");
    textArea.append(nodeTitle.toString() + "\n");
    //StringBuffer buf = new StringBuffer();
    //for(int j=0; j< nodeTitle.length(); j++)
    //buf.append("-");
    //textArea.append(buf.toString()  + "\n");
    for(int i=1; i< content.length; i++){
      //textArea.append
      textArea.append(title[i] + " :"  + "\n");
      textArea.append(content[i]  + "\n");
      textArea.append("\n");
    }

    textArea.append("Links: \n");
    for(Enumeration e = node.getConnectedLinks().elements();e.hasMoreElements();){
      CaseLink link = (CaseLink) e.nextElement();
      textArea.append(link.getClass().getName() + " : ");
      textArea.append(link.getLinkLabel());
      CaseNode peerNode;
      if(node.equals(link.getStartNode())){
        peerNode = link.getEndNode();
        textArea.append(" to ");
      }
      else{
        peerNode = link.getStartNode();
        textArea.append(" from ");
      }
      textArea.append(peerNode.getName());
      textArea.append(" : ");
      textArea.append((peerNode.getContent())[0] + "\n");
    }
  }

  /*public static void main(String argc[])
  {
    CaseEditorDocDialog dlg = new CaseEditorDocDialog();
    dlg.setVisible(true);
  }*/
} // end of class CaseEditorDocDialog.java
